<template>
	<view style="margin-left:10rpx;margin-right: 10rpx;">
		<view v-for="(item , index) in pages" :key="index">
			<!-- 轮播图 -->
			<view v-if="item.type == 'banner'" class="m-t-b-sm">
				<Banner :image="item.data"></Banner>
			</view>

			<!-- 三公图 -->
			<view v-if="item.type == 'blockMenu3'" class="m-t-b-sm">
				<BlockSan3 :list="item.data"></BlockSan3>
			</view>

			<view v-if="item.type == 'buttonLink' && item.data.show==true" class="m-t-b-sm">
				<navigator :url="item.data.url">
					<u-button :type='item.data.type'>{{item.data.name}}</u-button>
				</navigator>
			</view>

			<!-- 店铺列表 -->
			<ShopList :list="item.data" v-if="item.type == 'shopList'"></ShopList>
		</view>
	</view>
</template>

<script>
	import Banner from "@/components/banner/banner.vue"
	import BlockSan3 from "@/components/menu/blockScan3.vue"
	import ShopList from "@/components/list/shopList.vue"
	import fetch from '@/utils/http/fetch.js'

	export default {
		components: {
			Banner,
			BlockSan3,
			ShopList,
		},
		data() {
			return {
				pages: []
			}
		},


		async onShow() {
			if (this.pages) {
				for (var item of this.pages) {
					console.log(item)
					if (item.async && item.onShow) {
						item.url = 'Home/index'
						let res = await fetch('/api/common/asyncData', 'GET', item)
						item.data = res.data
					}
				}
			}

		},
		async onLoad(options) {
			uni.showLoading({
				title: '正在加载'
			})
			await this.$onLaunched
			uni.hideLoading()
			let publicConfig = uni.getStorageSync('publicConfig');
			console.log('首页获取配置信息', publicConfig)
			this.pages = publicConfig.pages['Home/index'].pages
			for (var item of this.pages) {
				if (item.async) {
					item.url = 'Home/index'
					let res = await fetch('/api/common/asyncData', 'GET', item)
					item.data = res.data
				}
			}
			this.activity(options)
		},
		methods: {
			async activity(options) {
				console.log('处理活动')
				if(options.activity_id != undefined){
					//去领取
					let res = await fetch('/api/market/activity', 'GET', options)
					uni.showModal({
						title:res.message
					})
				}
			}
		}

	}
</script>

<style>
</style>